﻿using System;
using System.Collections.Generic;
using System.Text;

namespace SharpSoft.Data
{
    using SharpSoft.Data.Expressions;
    using SharpSoft.Data.GSQL;
    public class SqliteTextGenerator : SQLTextGenerator
    {
        protected override string ProcessExpression(BinaryExpression bin)
        {
            return base.ProcessExpression(bin);
        }

        protected override string ProcessColumnDefine(ColumnDefine columnDefine)
        {
            columnDefine.Comment = null;//SQLITE不支持列备注
            return base.ProcessColumnDefine(columnDefine);
        }

        protected override string ColumnAutoincrement()
        {
            return "AUTOINCREMENT";
        }

        protected override string ProcessDataType(DataType dataType)
        {
            if (dataType == DataType.Int)
            {
                return "INTEGER";
            }
            return base.ProcessDataType(dataType);
        }

        protected override string ProcessExpression(BooleanExpression BO)
        {
            return BO.Content ? "1" : "0";
        }

        protected override string ProcessExpression(FunctionExpression func)
        {
            string funcname = func.Name.ToLower();
            switch (funcname)
            {
                case "lastid":
                    return "last_insert_rowid()";
                case "now":
                    return "(datetime('now', 'localtime'))";
                default:
                    return base.ProcessExpression(func);
            }
        }
        protected override string ProcessStatement(CreateTableStatement statement)
        {
            return base.ProcessStatement(statement);
        }

        protected override string ProcessConstraintDefine(ConstraintDefine constraintDefine)
        {
            throw new Exception("SQLITE不支持复杂的约束.");
            //return "";
        }
    }
}
